package com.foreknow.service.impl;

import com.foreknow.dao.BaseDao;
import com.foreknow.dao.impl.UserDaoImpl;
import com.foreknow.entity.User;
import com.foreknow.service.UserService;

import java.sql.SQLException;
import java.util.List;

public class UserServiceImpl implements UserService {

    @Override
    public User welcome(String username, String password) {
        BaseDao<User> baseDao= new UserDaoImpl();
        String sql = "select * from user  where username=? and password=?";
        User user = null;
        try {
         user= baseDao.queryOne(sql,username,password);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return user;
    }

    @Override
    public boolean add(User user) {
        BaseDao<User> baseDao= new UserDaoImpl();
        String sql ="insert into user(username,password,account,email,phone,avatar) values (?,?,?,?,?,?)";
        int isRight=0;
        try {
         isRight=  baseDao.insert(sql,user.getUsername(),user.getPassword(),user.getAccount(),user.getAvatar(),user.getEmail(),user.getPhone());
        } catch (SQLException e) {
            e.printStackTrace();
        }
         return  isRight==1;
    }
}
